#include "widget.h"
#include <QVBoxLayout>
#include <QScrollArea>
#include <QThread>
#include <QTimer>
#include "indcog.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->setMinimumWidth(800);
    this->setMinimumHeight(600);

    // 整体采用垂直布局
    QVBoxLayout* vLayout = new QVBoxLayout(this);
    vLayout->setContentsMargins(0, 0, 0, 0);

    // 使用QScrollArea可以滚动显示
    QScrollArea* scrollArea = new QScrollArea(this);
    scrollArea->setWidgetResizable(true);

    QWidget* scrollAreaContents = new QWidget(this);

    _gridLayout = new QGridLayout(scrollAreaContents);
    _gridLayout->setSpacing(0);
    _gridLayout->setContentsMargins(0, 0, 0, 0);

    scrollArea->setWidget(scrollAreaContents);
    vLayout->addWidget(scrollArea);

    addShim00();
    addShim01();
    addShim02();
    addShim10();
    addShim11();
    addShim12();
}

Widget::~Widget() {}

void Widget::addShim00()
{
    // Shimming* shimming = new Shimming(this);
    // shimming->setFixedSize(400, 376);
    // _gridLayout->addWidget(shimming, 0, 0);
    // shimming->setStyleSheet("background-color: rgb(200, 200, 200)");
    // shimming->SetCOGLocation(-10, -10);

    // std::vector<int> nodes = {1, 2, 3, 4};
    // shimming->SetNodesNumber(nodes);
    // shimming->SetPolygonType(Shimming::PolygonType::NONE_REGULAR);
}

void Widget::addShim01()
{
    IndCog* cog = new IndCog(this);
    //cog->setFixedSize(800, 376);
    //cog->setStyleSheet("background-color: rgb(255, 255, 255)");
    // shimming = new IndShimming(this);
    // shimming->setFixedSize(800, 376);
    _gridLayout->addWidget(cog, 0, 1);
    // shimming->setStyleSheet("background-color: rgb(200, 200, 200)");
    // shimming->SetCOGLocation(-80, 80);

    // std::vector<char> nodes = {7, 2, 3, 1};
    // shimming->SetNodesNumber(nodes);
    // shimming->ShowBlueTriangle(3);
    // shimming->SetHighlight(3);
    // shimming->SetCellCounts({100, 200, 300, 100});
    // shimming->SetLoadType(IndShimming::LoadType::RATIO);
    // shimming->SetPolygonType(IndShimming::PolygonType::NONE_REGULAR);
    // shimming->SetWidthHeightRatio(1.0);
}

void Widget::addShim02()
{
    // Shimming* shimming = new Shimming(this);
    // _gridLayout->addWidget(shimming, 0, 2);
    // shimming->setStyleSheet("background-color: rgb(180, 180, 180)");
}

void Widget::addShim10()
{
    // Shimming* shimming = new Shimming(this);
    // _gridLayout->addWidget(shimming, 1, 0);
}

void Widget::addShim11()
{
    // Shimming* shimming = new Shimming(this);
    // _gridLayout->addWidget(shimming, 1, 1);
}

void Widget::addShim12()
{
    // Shimming* shimming = new Shimming(this);
    // _gridLayout->addWidget(shimming, 1, 2);
}
